#region File Description

//-----------------------------------------------------------------------------
// OptionsMenuScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------

#endregion

#region Using Statements

using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Audio;

#endregion

namespace M1Xonix
{
    /// <summary>
    /// The options screen is brought up over the top of the main menu
    /// screen, and gives the user a chance to configure the game
    /// in various hopefully useful ways.
    /// </summary>
    internal class OptionsMenuScreen : MenuScreen
    {
        #region Fields

        
        private static bool music = true;
        private static bool sounds = true;

        
        private readonly MenuEntry musicMenuEntry;
        private readonly MenuEntry soundsMenuEntry;


        #endregion

        #region Initialization

        /// <summary>
        /// Constructor.
        /// </summary>
        public OptionsMenuScreen()
            : base("Options")
        {
            // Create our menu entries.
            
            musicMenuEntry = new MenuEntry(string.Empty);
            soundsMenuEntry = new MenuEntry(string.Empty);

            SetMenuEntryText();

            var back = new MenuEntry("Back");

            // Hook up menu event handlers.
            
            musicMenuEntry.Selected += MusicMenuEntrySelected;
            soundsMenuEntry.Selected += SoundsMenuEntrySelected;
            back.Selected += OnCancel;
            

            // Add entries to the menu.
            
            MenuEntries.Add(musicMenuEntry);
            MenuEntries.Add(soundsMenuEntry);
            MenuEntries.Add(back);
        }


        /// <summary>
        /// Fills in the latest values for the options screen menu text.
        /// </summary>
        private void SetMenuEntryText()
        {
            
            musicMenuEntry.Text = "Music: " + (music ? "on" : "off");
            soundsMenuEntry.Text = "Soundeffects: " + (sounds ? "on" : "off");
        }

        #endregion

        #region Handle Input

        

        /// <summary>
        /// Event handler for when the Music menu entry is selected
        /// </summary>
        private void MusicMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            music = !music;
            MediaPlayer.IsMuted = !music;

            SetMenuEntryText();
        }
        /// <summary>
        /// Event handler for when the Sounds menu entry is selected
        /// </summary>
        private void SoundsMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            sounds = !sounds;
            if (sounds) SoundEffect.MasterVolume = 1.0f;
            else SoundEffect.MasterVolume = 0f;
            SetMenuEntryText();
        }

        #endregion
    }
}